# -*- coding: utf-8 -*-
# @Time : 2019/2/20 10:21
# @Author : Administrator
# @File : pillow_demo.py
# @Project : 图像识别
# @title : pillow库的应用
from PIL import ImageGrab,Image
import os

# 1.抓取当前页面截取，并保存到内存，获取颜色值
screen = ImageGrab.grab().convert('RGBA')  # 抓取当前页面截图，并保存到内存
screen_data = screen.load()  # 获取图片颜色值元数据
width, height = screen.size   # 获取图片的宽、高
for i in range(width):
    for j in range(height):
        print(screen_data[i,j])  # 获取指定坐标的颜色值

# 2.获取图片某坐标的颜色值
screen_path = os.path.abspath('')+'\\screenshot\\20190219_172831.png'  # 获取图片路径
screen = Image.open(screen_path)   # 打开硬盘中的图片
width,height = screen.size   # 获取图片的宽、高
print(width,height)
screen_data = screen.load()     # 获取图片颜色值元数据
for i in range(width):
    for j in range(height):
        print(screen_data[i,j])
